<template>
    <Modal v-model="modal.show" :title="modal.title" footer-hide>
        <TableList :data="questionList" :columns="columns"></TableList>
    </Modal>
</template>
<script>
    import { escape2Html } from '@/libs/utils';
    import { queryCtfTargetAllot } from '@/api/drill_compete'
    export default {
        name:'QuestionModal',
        props:{
            
        },
        data(){
            return {
                modal:{
                    show:false,
                    title:'题目列表'
                },
                questionList:[],
                columns:[
                    {
                        type: 'html',
                        title:'题目名称',
                        key:'questionName',
                        filter: (description) => {
                            return this.escape2Html(description);
                        }
                    },
                    {
                        title:'完成情况',
                        key:'finishStatus',
                        filter:(finishStatus) => {
                            return finishStatus ? '已完成' : '未完成'
                        },
                        setColor:(finishStatus) => {
                            return finishStatus ? 'var(--status-yes)' : 'var(--status-no)'
                        }
                    },
                ]
            }
        },
        watch:{
            
        },
        methods:{
            openModal(contestId){
                this.modal.show = true;
                this.getCtfQuestion(contestId)
            },
            getCtfQuestion(contestId){
                let params = {
                    pageIndex:1,
                    pageSize:2147483647,
                    sceneId:contestId,
                }
                queryCtfTargetAllot(params).then(data => {
                    if(data.code==1){
                        this.questionList = data.data.items;
                    }else{
                        this.questionList = [];
                        this.$Message.error(data.message);
                    }
                }).catch(error => {
                    this.questionList = [];
                })
            },
            escape2Html(str, needReplace) {
                if(!str){
                    return 
                }
                let repStr = str.replace(/\{\{.*?\}\}/g, '___');
                if (needReplace) {
                    return escape2Html(repStr);
                } else {
                    return repStr;
                }
            },
        }
    }
</script>